﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QLLopHoc.DoiTuongDuLieu;
using System.Data;

namespace QLLopHoc.KetNoiDatabase
{
    public class KNChiTietLH
    {
        //phuong thuc lay ra danh sach ma sinh vien cua 1 lop
        public static List<string> LayDSMaSVCuaLH(string tenLH)
        {
            List<string> kq = new List<string>();
            string sql = "SELECT MSSV FROM ChiTietLopHoc WHERE TenLopHoc='" + tenLH + "'";
            DataTable dt = DataAccess.ExecQuery(sql);
            foreach (DataRow dr in dt.Rows)
            {
                kq.Add((string)dr["MSSV"]);
            }
            return kq;
        }
        //phuong thuc lay ra danh sach ten lop hoc tu ma sinh vien
        public static List<string> LayDSMaLHCuaSV(string mssv)
        {
            List<string> kq = new List<string>();
            string sql = "SELECT TenLopHoc FROM ChiTietLopHoc WHERE MSSV='" + mssv + "'";
            DataTable dt = DataAccess.ExecQuery(sql);
            foreach (DataRow dr in dt.Rows)
            {
                kq.Add((string)dr["TenLopHoc"]);
            }
            return kq;
        }
        //phuong thuc them 1 chi tiet lop hoc
        public static bool ThemChiTietLH(DTChiTietLH ctlh)
        {
            string sql = "INSERT INTO ChiTietLopHoc(TenLopHoc,MSSV) VALUSE ('" + ctlh.TenLopHoc + "','" + ctlh.MSSV + "'";
            if (DataAccess.ExecuteNonQuery(sql) > 0)
            {
                return true;
            }
            return false;
        }
        //phuong thuc xoa chi tiet lop hoc
        public static bool XoaChiTietLopHoc(DTChiTietLH ctlh)
        {
            string sql = "DELETE FROM ChiTietLopHoc WHERE tenLopHoc='" + ctlh.TenLopHoc + "'AND'" + "MSSV" + ctlh.MSSV + "'";
            if (DataAccess.ExecuteNonQuery(sql) > 0)
            {
                return true;
            }
            return false;
        }

        internal static bool XoaChiTietLH(DTChiTietLH ctlh)
        {
            throw new NotImplementedException();
        }
    }
}
